﻿var prog_name = "krj_document_category.js";

function SelectRows() {
    try {
        if (!$(".SelectedRow").length > 0) {
            alert('請選取一筆資料!!');
            return false;
        }
        else
            return true;
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "SelectRows", "USER", "js", err);
        return false;
    }

}

function btnSearch_Click(p_PageIndex) {
    try {
        var sType = '';
        var sORDER = '';
        var sFunction = '';

        //頁次
        var m_PageIndex = getPageIndex(p_PageIndex);

        sORDER = 'dept_id,document_category';
        sFunction = "Getdocument_category";
        //查詢條件 對應後端查詢條件
        
        var StrWhere = { DEPT_ID: $("#MainContent_ddldept option:selected").val(), CATEGORY_ID: $("#MainContent_txtCategory").val(), CATEGORY_NAME: $("#MainContent_txtCategory_NAME").val() };

        $("#DocumentPageControl").attr("GridWidth", "20%,20%,60%");
        $("#DocumentPageControl").attr("textalign", "C,C,,C");
        $("#DocumentPageControl").attr("HideColumn", "DEPT_ID_H");

        //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
        gdb_DataBind("krj_document_category", sFunction, m_PageIndex, "15", sORDER, StrWhere, "Document");


        $("div[id='Document']").show();
        $("div[id='divPageinfo']").show();

        $("#MainContent_btn_edit").show();
        $("#MainContent_btn_delete").show();
        $("#MainContent_btnView").show();
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "btnSearch_Click", "USER", "js", err);
        return false;
    }
}


function showModalPopupViaClient(ev) {
    try {
    var DEPT = "";
    DEPT = $("#MainContent_ddldept option:selected").val();

    var sORDER = '';
    sORDER = 'dept_id,category_id';
    //頁次
    //alert($("#MainContent_TabContainer2_TabPanel5_lblDetail_NO").html());
    //查詢條件 對應後端查詢條件
    var StrWhere = { DEPT_ID: DEPT };
    $("#mislandedPageControl").attr("GridWidth", "30%,35%,35%");
    $("#mislandedPageControl").attr("textalign", "C,C,C");
    $("#mislandedPageControl").attr("HideColumn", "");
    //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
    gdb_DataBind("krj_document_category", "qtyCATEGORY", "1", "10", sORDER, StrWhere, "CATEGORY");


    var modalPopupBehavior = $("#ModalPopupExtender1");
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "showModalPopupViaClient", "USER", "js", err);
        return false;
    }

}

function hideModalPopupViaClient(ev) {

}

function select(e, p_TargetDiv) {
    try {
        //擷取觸發控制項
        var obj = GetEvent(e);
        var sVALUE = "";
        switch (obj.tagName) {
            case "TD":
                if ($("#" + obj.id).parent().length > 0) {
                    var m_TrId = $("#" + obj.id).parent()[0].id;
                    SelectedRow(p_TargetDiv, m_TrId);
                    sVALUE = $.trim($("#" + obj.id).parent()[0].cells[0].innerText).substring(0, 4);

                    $("#MainContent_txtCategory").val($.trim($("#" + obj.id).parent()[0].cells[1].innerText));
                    $("#MainContent_txtCategory_NAME").val($.trim($("#" + obj.id).parent()[0].cells[2].innerText));
                    $('#MainContent_ddldept option[value=' + sVALUE + ']').attr('selected', true);
                    $("#MainContent_txtCategory").change();
                    $("#MainContent_btnClose")[0].click();
                }
                break;
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "select", "USER", "js", err);
        return false;
    }
}